# if the image has not been build, build it first
#!/bin/bash

# Step 1: Check if the Docker image "rusty" exists
if docker images | grep -q "rusty"; then
    echo "Docker image 'rusty' already exists."
else
    echo "Docker image 'rusty' does not exist. Building it now..."
    
    # Step 2: Build the Docker image
    docker build -t rusty -f Dockerfile ./Tool
    
    # Check if the build was successful
    if [ $? -eq 0 ]; then
        echo "Docker image 'rusty' built successfully."
    else
        echo "Failed to build Docker image 'rusty'."
        exit 1
    fi
fi

# Step 3: Run the Docker container with mounts and attach the shell
docker run -it \
    -v "$(pwd)/Input:/app/input" \
    -v "$(pwd)/Output:/app/output" \
    -v "$(pwd)/run.sh:/app/run.sh" \
    rusty \
    /bin/bash